/*
 * @lc app=leetcode.cn id=50 lang=cpp
 *
 * [50] Pow(x, n)
 */

// @lc code=start
class Solution {
public:
    double quickMul(double x,long long N) {
        if(N == 0) {
            return 1.0;
        }
        double y = quickMul(x,N/2);
        //y = x^(N/2)
        //幂次偶数的话就改两个相同的数相乘比如x^4 = x^2*x^2，
        //N是奇数的话就比如x^5 = x^2*x^2*x
        return N % 2 == 0 ? y * y : y * y * x;
    }
    double myPow(double x, int n) {
        long long N = n;
        return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N);
    }
};
// @lc code=end

